/*
Date:20220224 16:44PM
key:经典动态规划 注意相加时区别矩阵与dp矩阵
*/
class Solution {
public:
    int maxValue(vector<vector<int>>& grid) {
    vector<vector<int>>dp(grid.begin(),grid.end());
    for(int i=1;i<dp.size();i++){
        dp[i][0]=dp[i-1][0]+grid[i][0];
    }
    for(int i=1;i<dp[0].size();i++){
        dp[0][i]=dp[0][i-1]+grid[0][i];
        
    }
    for(int i=1;i<dp.size();i++)
    {
        for(int j=1;j<dp[0].size();j++)
        {
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+grid[i][j];
            //cout<<dp[i][j]<<"\t";
        }
    }
    return dp[dp.size()-1][dp[0].size()-1];
    }
};